<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
</body>
<script>
    function foo(arr){
        let AMOUNT = arr.length;
        if(!AMOUNT) return false;
        if(AMOUNT ===3) return arr;
        arr.sort((a,b)=>a-b);
        let total =0;
        let maxNumberTotal = 0;
        for(let i =0;i<AMOUNT;i++){
            total += arr[i];
        }
        maxNumberTotal  = total/3;
        let tempTotal = arr[AMOUNT -1];

        let firstArr = [arr[AMOUNT -1]];
        let delIndex = [AMOUNT -1];
        let firstIndex = -1;

        //获取第一份数组
        for(let i = AMOUNT -2;i>0;i--){
            const el = arr[i];
            tempTotal +=el;  //每次拿最大的；
            firstArr.push(el);
            delIndex.push(i);
            if(tempTotal === maxNumberTotal){ //刚好等于最大值跳出循环
                break;
            }else if(tempTotal >maxNumberTotal){ //发现超过最大值，减回去
                tempTotal -=el;
                delIndex.pop();
                firstArr.pop()
            }
        }
    }
</script>
</html>